home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / uucp / AM114src.lha / editab.c < prev    next >
C/C++ Source or Header  |  1992-07-20  |  23KB  |  906 lines

  1. /*
  2.  *
  3.  *  AM --- AmigaMail
  4.  *  (C) 1991, 1992 by Christian Riede
  5.  *
  6.  *  AM is distributed in the hope that it will be useful, but WITHOUT ANY
  7.  *  WARRANTY.  No author or distributor accepts responsibility to anyone
  8.  *  for the consequences of using it or for whether it serves any
  9.  *  particular purpose or works at all, unless he says so in writing.
  10.  *  Refer to the GNU General Public License, Version 1, for full details.
  11.  *  
  12.  *  Everyone is granted permission to copy, modify and redistribute AM,
  13.  *  but only under the conditions described in the GNU General Public
  14.  *  License, Version 1.  A copy of this license is supposed to have been 
  15.  *  given to you along with AM so you can know your rights and responsi-
  16.  *  bilities.  It should be in a file named COPYING.  Among other things,
  17.  *  the copyright notice and this notice must be preserved on all copies.
  18.  *
  19.  *  
  20.  *
  21.  */
  22.  
  23.  
  24. #include "am.h"
  25.  
  26. #define EDIT_HEIGHT (8*(TextAttr.ta_YSize+6)+10)
  27.  
  28. #define NEXT      1
  29. #define PREVIOUS  2
  30. #define AB_SORT   3
  31. #define FIND      4
  32. #define CLEAR     5
  33. #define ADD       6
  34. #define UPDATE    7
  35. #define DELETE    8
  36. #define USERNAME  9
  37. #define REALNAME 10
  38. #define REPLYTO  11
  39. #define RRT      12
  40. #define CTE_     13
  41.  
  42. #define DEFAULT_CTE CTE_7BIT
  43.  
  44. static char *RRTLabels[] = {
  45. "Config Menu",
  46. "No",
  47. "Yes",
  48. 0
  49. };
  50.  
  51.  
  52. void EditAddressBook(void)
  53. {
  54.     int run,w,ActualRRT=-1,ActualCTE=DEFAULT_CTE;
  55.     struct IntuiMessage *Msg;
  56.     ULONG Class;
  57.     ULONG Code;
  58.     APTR IAddr;
  59.     struct Address *Address=0,*StartAddress;
  60.     struct List Addressbook;
  61.     struct Window *EditABWindow;
  62.     struct Gadget *GList,*gad;
  63.     struct Gadget *RRTGad,*CTEGad,*RealnameGad,*UsernameGad,*ReplyToGad;
  64.     struct Gadget *ActiveGadget;
  65.     char MyUsername[MAIL_FIELDLENGTH];
  66.     char MyRealname[MAIL_FIELDLENGTH];
  67.     int found;
  68.  
  69.     struct NewGadget NextGadget = 
  70.     {
  71.         0,0,0,0,
  72.         (UBYTE *)"Next",&TextAttr,
  73.         NEXT,
  74.         PLACETEXT_IN,
  75.         0,    
  76.         0
  77.     };
  78.     
  79.     struct NewGadget PreviousGadget = 
  80.     {
  81.         0,0,0,0,
  82.         (UBYTE *)"Previous",&TextAttr,
  83.         PREVIOUS,
  84.         PLACETEXT_IN,
  85.         0,    
  86.         0
  87.     };
  88.     
  89.     struct NewGadget SortGadget = 
  90.     {
  91.         0,0,0,0,
  92.         (UBYTE *)"Sort",&TextAttr,
  93.         AB_SORT,
  94.         PLACETEXT_IN,
  95.         0,    
  96.         0
  97.     };
  98.     
  99.     struct NewGadget FindGadget = 
  100.     {
  101.         0,0,0,0,
  102.         (UBYTE *)"Find",&TextAttr,
  103.         FIND,
  104.         PLACETEXT_IN,
  105.         0,    
  106.         0
  107.     };
  108.  
  109.     struct NewGadget ClearGadget = 
  110.     {
  111.         0,0,0,0,
  112.         (UBYTE *)"Clear",&TextAttr,
  113.         CLEAR,
  114.         PLACETEXT_IN,
  115.         0,    
  116.         0
  117.     };
  118.  
  119.     struct NewGadget ABAddGadget = 
  120.     {
  121.         0,0,0,0,
  122.         (UBYTE *)"Add",&TextAttr,
  123.         ADD,
  124.         PLACETEXT_IN,
  125.         0,    
  126.         0
  127.     };
  128.     
  129.     struct NewGadget UpdateGadget = 
  130.     {
  131.         0,0,0,0,
  132.         (UBYTE *)"Update",&TextAttr,
  133.         UPDATE,
  134.         PLACETEXT_IN,
  135.         0,    
  136.         0
  137.     };
  138.  
  139.     struct NewGadget DelGadget = 
  140.     {
  141.         0,0,0,0,
  142.         (UBYTE *)"Delete",&TextAttr,
  143.         DELETE,
  144.         PLACETEXT_IN,
  145.         0,    
  146.         0
  147.     };
  148.     
  149.     struct NewGadget UGadget = 
  150.     {
  151.         0,0,0,0,
  152.         (UBYTE *)"Username:",&TextAttr,
  153.         USERNAME,
  154.         PLACETEXT_LEFT,
  155.         0,    
  156.         0
  157.     };
  158.     
  159.     struct NewGadget RGadget = 
  160.     {
  161.         0,0,0,0,
  162.         (UBYTE *)"Realname:",&TextAttr,
  163.         REALNAME,
  164.         PLACETEXT_LEFT,
  165.         0,    
  166.         0
  167.     };
  168.  
  169.     struct NewGadget ReplyToGadget = 
  170.     {
  171.         0,0,0,0,
  172.         (UBYTE *)"Reply-To:",&TextAttr,
  173.         REPLYTO,
  174.         PLACETEXT_LEFT,
  175.         0,    
  176.         0
  177.     };
  178.     
  179.     struct NewGadget RRTGadget = 
  180.     {
  181.         0,0,0,0,
  182.         (UBYTE *)"Return-Receipt-To:",&TextAttr,
  183.         RRT,
  184.         PLACETEXT_LEFT,
  185.         0,    
  186.         0
  187.     };
  188.     
  189.     struct NewGadget CTEGadget = 
  190.     {
  191.         0,0,0,0,
  192.         (UBYTE *)"Contents-Type-Encoding:",&TextAttr,
  193.         CTE_,
  194.         PLACETEXT_LEFT,
  195.         0,    
  196.         0
  197.     };
  198.     
  199.     
  200.     if (Screen) /* custom screen requested */
  201.     {
  202.         if (!(EditABWindow = OpenWindowTags(0,
  203.             WA_CustomScreen,Screen,
  204.             WA_Left,ABLeft,
  205.             WA_Top,ABTop,
  206.             WA_Width,ABWidth,
  207.             WA_Height,EDIT_HEIGHT,
  208.             WA_MinWidth,640L,
  209.             WA_MinHeight,180L,
  210.             WA_MaxWidth,1024L,
  211.             WA_MaxHeight,1024L,
  212.             WA_DragBar,TRUE,
  213.             WA_DepthGadget,TRUE,
  214.             WA_CloseGadget,TRUE,
  215.             WA_Activate,TRUE,
  216.             WA_SmartRefresh,TRUE,
  217.             WA_GimmeZeroZero,TRUE,
  218.             WA_Title,"Edit Addressbook",
  219.             WA_RMBTrap,TRUE,
  220.             TAG_END)))
  221.         {
  222.             FreeAddressBook(&Addressbook);
  223.             SimpleRequest(Window,"Can't open Addressbook-Window");
  224.             return;
  225.         }
  226.     }
  227.     else if (PubScreen) /* public screen requested */
  228.     {
  229.         if (!(EditABWindow = OpenWindowTags(0,
  230.             WA_PubScreen,(UBYTE *)PubScreen,
  231.             WA_Left,ABLeft,
  232.             WA_Top,ABTop,
  233.             WA_Width,ABWidth,
  234.             WA_Height,ABHeight1,
  235.             WA_MinWidth,640L,
  236.             WA_MinHeight,180L,
  237.             WA_MaxWidth,1024L,
  238.             WA_MaxHeight,1024L,
  239.             WA_DragBar,TRUE,
  240.             WA_DepthGadget,TRUE,
  241.             WA_CloseGadget,TRUE,
  242.             WA_Activate,TRUE,
  243.             WA_SmartRefresh,TRUE,
  244.             WA_GimmeZeroZero,TRUE,
  245.             WA_Title,"Edit Addressbook",
  246.             WA_RMBTrap,TRUE,
  247.             TAG_END)))
  248.         {
  249.             FreeAddressBook(&Addressbook);
  250.             SimpleRequest(Window,"Can't open Addressbook-Window");
  251.             return;
  252.         }
  253.         
  254.     }
  255.     else
  256.         return;
  257.  
  258.     /* read addressbook */
  259.     ReadAddressBook(&Addressbook);
  260.  
  261.     GList = 0;
  262.  
  263.  
  264.     /* get visualinfo */
  265.     if(!(NextGadget.ng_VisualInfo = GetVisualInfo(EditABWindow->WScreen,TAG_END)))
  266.     {
  267.         SimpleRequest(Window,"Can't get visual info");
  268.         FreeAddressBook(&Addressbook);
  269.         CloseWindow(EditABWindow);
  270.         return;
  271.     }
  272.  
  273.     PreviousGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  274.     SortGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  275.     FindGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  276.     ClearGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  277.     ABAddGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  278.     UpdateGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  279.     DelGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  280.     UGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  281.     RGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  282.     ReplyToGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  283.     RRTGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  284.     CTEGadget.ng_VisualInfo = NextGadget.ng_VisualInfo;
  285.  
  286.     /* allocate context */
  287.     if (!(gad = CreateContext(&GList)))
  288.     {
  289.             CloseWindow(EditABWindow);
  290.             FreeAddressBook(&Addressbook);
  291.             SimpleRequest(Window,"Can't create context");
  292.             return;
  293.     }
  294.  
  295.     /* adjust gadgets to window dimensions */
  296.     ClearGadget.ng_LeftEdge = 5;
  297.     ClearGadget.ng_TopEdge = EditABWindow->GZZHeight-TextAttr.ta_YSize-8;
  298.     ClearGadget.ng_Width = 100;                           /* !!!!!!!!!!!!!!! */
  299.     ClearGadget.ng_Height = TextAttr.ta_YSize+4;
  300.  
  301.     DelGadget.ng_LeftEdge = EditABWindow->GZZWidth-ClearGadget.ng_Width-ClearGadget.ng_LeftEdge-5;
  302.     DelGadget.ng_TopEdge = ClearGadget.ng_TopEdge;
  303.     DelGadget.ng_Width = ClearGadget.ng_Width;
  304.     DelGadget.ng_Height = ClearGadget.ng_Height;
  305.  
  306.     w = (DelGadget.ng_LeftEdge-ClearGadget.ng_Width-ClearGadget.ng_LeftEdge)/2;
  307.  
  308.     ABAddGadget.ng_LeftEdge = ClearGadget.ng_Width+ClearGadget.ng_LeftEdge
  309.         + w/2 - ClearGadget.ng_Width/2;
  310.     ABAddGadget.ng_TopEdge = ClearGadget.ng_TopEdge;
  311.     ABAddGadget.ng_Width = ClearGadget.ng_Width;
  312.     ABAddGadget.ng_Height = ClearGadget.ng_Height;
  313.  
  314.     UpdateGadget.ng_LeftEdge = ClearGadget.ng_Width+ClearGadget.ng_LeftEdge
  315.         + w/2 + w - ClearGadget.ng_Width/2;
  316.     UpdateGadget.ng_TopEdge = ClearGadget.ng_TopEdge;
  317.     UpdateGadget.ng_Width = ClearGadget.ng_Width;
  318.     UpdateGadget.ng_Height = ClearGadget.ng_Height;
  319.  
  320.     PreviousGadget.ng_LeftEdge = ClearGadget.ng_LeftEdge;
  321.     PreviousGadget.ng_TopEdge = ClearGadget.ng_TopEdge-TextAttr.ta_YSize-8;
  322.     PreviousGadget.ng_Width = ClearGadget.ng_Width;
  323.     PreviousGadget.ng_Height = ClearGadget.ng_Height;
  324.  
  325.     NextGadget.ng_LeftEdge = EditABWindow->GZZWidth-PreviousGadget.ng_Width
  326.         -PreviousGadget.ng_LeftEdge-5;
  327.     NextGadget.ng_TopEdge = PreviousGadget.ng_TopEdge;
  328.     NextGadget.ng_Width = PreviousGadget.ng_Width;
  329.     NextGadget.ng_Height = PreviousGadget.ng_Height;
  330.  
  331.     w = (NextGadget.ng_LeftEdge-PreviousGadget.ng_Width-PreviousGadget.ng_LeftEdge)/2;
  332.  
  333.     FindGadget.ng_LeftEdge = PreviousGadget.ng_Width+PreviousGadget.ng_LeftEdge
  334.         + w/2 - PreviousGadget.ng_Width/2;
  335.     FindGadget.ng_TopEdge = PreviousGadget.ng_TopEdge;
  336.     FindGadget.ng_Width = PreviousGadget.ng_Width;
  337.     FindGadget.ng_Height = PreviousGadget.ng_Height;
  338.  
  339.     SortGadget.ng_LeftEdge = PreviousGadget.ng_LeftEdge+PreviousGadget.ng_Width
  340.         + w + w/2 - PreviousGadget.ng_Width/2;
  341.     SortGadget.ng_TopEdge = PreviousGadget.ng_TopEdge;
  342.     SortGadget.ng_Width = PreviousGadget.ng_Width;
  343.     SortGadget.ng_Height = PreviousGadget.ng_Height;
  344.  
  345.     RRTGadget.ng_LeftEdge = EditABWindow->GZZWidth/2-150/2;
  346.     RRTGadget.ng_TopEdge = PreviousGadget.ng_TopEdge-TextAttr.ta_YSize-6;
  347.     RRTGadget.ng_Width = 150;
  348.     RRTGadget.ng_Height = TextAttr.ta_YSize+4;
  349.  
  350.     CTEGadget.ng_LeftEdge = EditABWindow->GZZWidth/2-150/2;
  351.     CTEGadget.ng_TopEdge = RRTGadget.ng_TopEdge-TextAttr.ta_YSize-6;
  352.     CTEGadget.ng_Width = 150;
  353.     CTEGadget.ng_Height = TextAttr.ta_YSize+4;
  354.  
  355.     ReplyToGadget.ng_LeftEdge = 100;
  356.     ReplyToGadget.ng_TopEdge = CTEGadget.ng_TopEdge-TextAttr.ta_YSize-6;
  357.     ReplyToGadget.ng_Width = EditABWindow->GZZWidth-105;
  358.     ReplyToGadget.ng_Height = TextAttr.ta_YSize+4;
  359.  
  360.     RGadget.ng_LeftEdge = 100;
  361.     RGadget.ng_TopEdge = ReplyToGadget.ng_TopEdge-TextAttr.ta_YSize-6;
  362.     RGadget.ng_Width = EditABWindow->GZZWidth-105;
  363.     RGadget.ng_Height = TextAttr.ta_YSize+4;
  364.  
  365.     UGadget.ng_LeftEdge = 100;
  366.     UGadget.ng_TopEdge = RGadget.ng_TopEdge-TextAttr.ta_YSize-6;
  367.     UGadget.ng_Width = EditABWindow->GZZWidth-105;
  368.     UGadget.ng_Height = TextAttr.ta_YSize+4;
  369.  
  370.     /* create Clear gadget */
  371.     if(!(gad = CreateGadget(BUTTON_KIND,gad,&ClearGadget,
  372.         GA_RELVERIFY,TRUE,
  373.         TAG_END)))
  374.     {
  375.             CloseWindow(EditABWindow);
  376.             FreeAddressBook(&Addressbook);
  377.             SimpleRequest(Window,"Can't create Clear gadget");
  378.             return;
  379.     }
  380.  
  381.     /* create Add gadget */
  382.     if(!(gad = CreateGadget(BUTTON_KIND,gad,&ABAddGadget,
  383.         GA_RELVERIFY,TRUE,
  384.         TAG_END)))
  385.     {
  386.             CloseWindow(EditABWindow);
  387.             FreeAddressBook(&Addressbook);
  388.             SimpleRequest(Window,"Can't create Add gadget");
  389.             return;
  390.     }
  391.  
  392.     /* create Update gadget */
  393.     if(!(gad = CreateGadget(BUTTON_KIND,gad,&UpdateGadget,
  394.         GA_RELVERIFY,TRUE,
  395.         TAG_END)))
  396.     {
  397.             CloseWindow(EditABWindow);
  398.             FreeAddressBook(&Addressbook);
  399.             SimpleRequest(Window,"Can't create Update gadget");
  400.             return;
  401.     }
  402.  
  403.     /* create Delete gadget */
  404.     if(!(gad = CreateGadget(BUTTON_KIND,gad,&DelGadget,
  405.         GA_RELVERIFY,TRUE,
  406.         TAG_END)))
  407.     {
  408.             CloseWindow(EditABWindow);
  409.             FreeAddressBook(&Addressbook);
  410.             SimpleRequest(Window,"Can't create Delete gadget");
  411.             return;
  412.     }
  413.  
  414.     
  415.     /* create Previous gadget */
  416.     if(!(gad = CreateGadget(BUTTON_KIND,gad,&PreviousGadget,
  417.         GA_RELVERIFY,TRUE,
  418.         TAG_END)))
  419.     {
  420.             CloseWindow(EditABWindow);
  421.             FreeAddressBook(&Addressbook);
  422.             SimpleRequest(Window,"Can't create Previous gadget");
  423.             return;
  424.     }
  425.  
  426.     /* create Next gadget */
  427.     if(!(gad = CreateGadget(BUTTON_KIND,gad,&NextGadget,
  428.         GA_RELVERIFY,TRUE,
  429.         TAG_END)))
  430.     {
  431.             CloseWindow(EditABWindow);
  432.             FreeAddressBook(&Addressbook);
  433.             SimpleRequest(Window,"Can't create Next gadget");
  434.             return;
  435.     }
  436.  
  437.  
  438.     /* create Sort gadget */
  439.     if(!(gad = CreateGadget(BUTTON_KIND,gad,&SortGadget,
  440.         GA_RELVERIFY,TRUE,
  441.         TAG_END)))
  442.     {
  443.             CloseWindow(EditABWindow);
  444.             FreeAddressBook(&Addressbook);
  445.             SimpleRequest(Window,"Can't create Sort gadget");
  446.             return;
  447.     }
  448.  
  449.  
  450.     /* create Find gadget */
  451.     if(!(gad = CreateGadget(BUTTON_KIND,gad,&FindGadget,
  452.         GA_RELVERIFY,TRUE,
  453.         TAG_END)))
  454.     {
  455.             CloseWindow(EditABWindow);
  456.             FreeAddressBook(&Addressbook);
  457.             SimpleRequest(Window,"Can't create Find gadget");
  458.             return;
  459.     }
  460.  
  461.  
  462.     /* create RRTGadget */
  463.     if (!(RRTGad = gad = CreateGadget(CYCLE_KIND,gad,&RRTGadget,
  464.         GTCY_Labels,RRTLabels,
  465.         GTCY_Active,0,
  466.         TAG_END)))
  467.     {
  468.             CloseWindow(EditABWindow);
  469.             FreeAddressBook(&Addressbook);
  470.             SimpleRequest(Window,"Can't create RRT gadget");
  471.             return;
  472.     }
  473.  
  474.     /* create CTEGadget */
  475.     if (!(CTEGad = gad = CreateGadget(CYCLE_KIND,gad,&CTEGadget,
  476.         GTCY_Labels,ContentTransferEncoding,
  477.         GTCY_Active,DEFAULT_CTE,
  478.         TAG_END)))
  479.     {
  480.             CloseWindow(EditABWindow);
  481.             FreeAddressBook(&Addressbook);
  482.             SimpleRequest(Window,"Can't create CTE gadget");
  483.             return;
  484.     }
  485.  
  486.     /* create ReplyToGadget */
  487.     if (!(ReplyToGad = gad = CreateGadget(STRING_KIND,gad,&ReplyToGadget,
  488.         GTST_MaxChars,MAIL_FIELDLENGTH,
  489.         TAG_END)))
  490.     {
  491.             CloseWindow(EditABWindow);
  492.             FreeAddressBook(&Addressbook);
  493.             SimpleRequest(Window,"Can't create ReplyTo gadget");
  494.             return;
  495.     }
  496.  
  497.     /* get RGadget */
  498.     if (!(RealnameGad = gad = CreateGadget(STRING_KIND,gad,&RGadget,
  499.         GTST_MaxChars,MAIL_FIELDLENGTH,
  500.         TAG_END)))
  501.     {
  502.             CloseWindow(EditABWindow);
  503.             FreeAddressBook(&Addressbook);
  504.             SimpleRequest(Window,"Can't create To gadget");
  505.             return;
  506.     }
  507.  
  508.     /* get Username-gadget */
  509.     if (!(UsernameGad = gad = CreateGadget(STRING_KIND,gad,&UGadget,
  510.         GTST_MaxChars,MAIL_FIELDLENGTH,
  511.         TAG_END)))
  512.     {
  513.             CloseWindow(EditABWindow);
  514.             FreeAddressBook(&Addressbook);
  515.             SimpleRequest(Window,"Can't create username gadget");
  516.             return;
  517.     }
  518.  
  519.     /* show up gadgets */
  520.     AddGList(EditABWindow,GList,-1,-1,NULL);
  521.     RefreshGList(GList,EditABWindow,NULL,-1);
  522.     GT_RefreshWindow(EditABWindow,0);
  523.  
  524.     ModifyIDCMP(EditABWindow,GADGETUP|CYCLEIDCMP|CLOSEWINDOW);
  525.  
  526.     ActiveGadget = UsernameGad;
  527.  
  528.     /* main loop */
  529.     ActivateGadget(ActiveGadget,EditABWindow,0);
  530.     run = TRUE;
  531.     while (run)
  532.     {
  533.         Wait(1L<<EditABWindow->UserPort->mp_SigBit);
  534.         while (Msg = GT_GetIMsg(EditABWindow->UserPort))
  535.         {
  536.             /* remember values */
  537.             Class = Msg->Class;
  538.             Code  = Msg->Code;    
  539.             IAddr = Msg->IAddress;
  540.  
  541.             /* reply message */
  542.             GT_ReplyIMsg(Msg);
  543.  
  544.             /* dispatch */
  545.             switch(Class)
  546.             {
  547.                 case REFRESHWINDOW:
  548.                     GT_BeginRefresh(EditABWindow);
  549.                     GT_EndRefresh(EditABWindow,TRUE);
  550.                     break;
  551.                 case CLOSEWINDOW:
  552.                     run = FALSE;
  553.                     break;
  554.                 case GADGETUP:
  555.                     switch(((struct Gadget *)IAddr)->GadgetID)
  556.                     {
  557.                         case USERNAME:
  558.                             ActiveGadget = RealnameGad;
  559.                             break;
  560.  
  561.                         case REALNAME:
  562.                             ActiveGadget = ReplyToGad;
  563.                             break;
  564.  
  565.                         case REPLYTO:
  566.                             ActiveGadget = UsernameGad;
  567.                             break;
  568.  
  569.                         case NEXT:
  570.                             if (Address)
  571.                                 AddTail(&Addressbook,&(Address->Node));
  572.  
  573.                             Address = (struct Address *)RemHead(&Addressbook);
  574.  
  575.                             if (Address)
  576.                             {
  577.                                 GT_SetGadgetAttrs(UsernameGad,EditABWindow,0,
  578.                                     GTST_String,Address->Username,
  579.                                     TAG_END);
  580.                                 GT_SetGadgetAttrs(RealnameGad,EditABWindow,0,
  581.                                     GTST_String,Address->Realname,
  582.                                     TAG_END);
  583.                                 GT_SetGadgetAttrs(ReplyToGad,EditABWindow,0,
  584.                                     GTST_String,Address->ReplyTo,
  585.                                     TAG_END);
  586.                                 GT_SetGadgetAttrs(RRTGad,EditABWindow,0,
  587.                                     GTCY_Active,Address->ReturnReceiptTo+1,
  588.                                     TAG_END);
  589.                                 GT_SetGadgetAttrs(CTEGad,EditABWindow,0,
  590.                                     GTCY_Active,Address->CTE,
  591.                                     TAG_END);
  592.                                 ActualRRT = Address->ReturnReceiptTo;
  593.                                 ActualCTE = Address->CTE;
  594.                             }
  595.                             else
  596.                             {
  597.                                 GT_SetGadgetAttrs(UsernameGad,EditABWindow,0,
  598.                                     GTST_String,"",
  599.                                     TAG_END);
  600.                                 GT_SetGadgetAttrs(RealnameGad,EditABWindow,0,
  601.                                     GTST_String,"",
  602.                                     TAG_END);
  603.                                 GT_SetGadgetAttrs(ReplyToGad,EditABWindow,0,
  604.                                     GTST_String,"",
  605.                                     TAG_END);
  606.                                 GT_SetGadgetAttrs(RRTGad,EditABWindow,0,
  607.                                     GTCY_Active,0,
  608.                                     TAG_END);
  609.                                 GT_SetGadgetAttrs(CTEGad,EditABWindow,0,
  610.                                     GTCY_Active,DEFAULT_CTE,
  611.                                     TAG_END);
  612.                                 ActualRRT = -1;
  613.                                 ActualCTE = DEFAULT_CTE;
  614.                             }
  615.                             ActiveGadget = UsernameGad;
  616.                             break;
  617.  
  618.                         case PREVIOUS:
  619.                             if (Address)
  620.                                 AddHead(&Addressbook,&(Address->Node));
  621.  
  622.                             Address = (struct Address *)RemTail(&Addressbook);
  623.  
  624.                             if (Address) if (Address->Node.ln_Pred)
  625.                             {
  626.                                 GT_SetGadgetAttrs(UsernameGad,EditABWindow,0,
  627.                                     GTST_String,Address->Username,
  628.                                     TAG_END);
  629.                                 GT_SetGadgetAttrs(RealnameGad,EditABWindow,0,
  630.                                     GTST_String,Address->Realname,
  631.                                     TAG_END);
  632.                                 GT_SetGadgetAttrs(ReplyToGad,EditABWindow,0,
  633.                                     GTST_String,Address->ReplyTo,
  634.                                     TAG_END);
  635.                                 GT_SetGadgetAttrs(RRTGad,EditABWindow,0,
  636.                                     GTCY_Active,Address->ReturnReceiptTo+1,
  637.                                     TAG_END);
  638.                                 GT_SetGadgetAttrs(CTEGad,EditABWindow,0,
  639.                                     GTCY_Active,Address->CTE,
  640.                                     TAG_END);
  641.                                 ActualRRT = Address->ReturnReceiptTo;
  642.                                 ActualCTE = Address->CTE;
  643.                             }
  644.                             else
  645.                             {
  646.                                 GT_SetGadgetAttrs(UsernameGad,EditABWindow,0,
  647.                                     GTST_String,"",
  648.                                     TAG_END);
  649.                                 GT_SetGadgetAttrs(RealnameGad,EditABWindow,0,
  650.                                     GTST_String,"",
  651.                                     TAG_END);
  652.                                 GT_SetGadgetAttrs(ReplyToGad,EditABWindow,0,
  653.                                     GTST_String,"",
  654.                                     TAG_END);
  655.                                 GT_SetGadgetAttrs(RRTGad,EditABWindow,0,
  656.                                     GTCY_Active,0,
  657.                                     TAG_END);
  658.                                 GT_SetGadgetAttrs(CTEGad,EditABWindow,0,
  659.                                     GTCY_Active,DEFAULT_CTE,
  660.                                     TAG_END);
  661.                                 ActualRRT = -1;
  662.                                 ActualCTE = DEFAULT_CTE;
  663.                             }
  664.                             ActiveGadget = UsernameGad;
  665.                             break;
  666.  
  667.                         case DELETE:
  668.                             if (Address)
  669.                             {
  670.                                 if (TwoGadRequest(EditABWindow,"Really delete?"))
  671.                                 {
  672.                                     FreeMem(Address->Node.ln_Name,160);
  673.                                     FreeMem(Address->Realname,160);
  674.                                     FreeMem(Address->Username,160);
  675.                                     FreeMem(Address->ReplyTo,160);
  676.                                     FreeMem(Address,sizeof(struct Address));
  677.                                     Address = 0;
  678.                                     GT_SetGadgetAttrs(UsernameGad,EditABWindow,0,
  679.                                         GTST_String,"",
  680.                                         TAG_END);
  681.                                     GT_SetGadgetAttrs(RealnameGad,EditABWindow,0,
  682.                                         GTST_String,"",
  683.                                         TAG_END);
  684.                                     GT_SetGadgetAttrs(ReplyToGad,EditABWindow,0,
  685.                                         GTST_String,"",
  686.                                         TAG_END);
  687.                                     GT_SetGadgetAttrs(RRTGad,EditABWindow,0,
  688.                                         GTCY_Active,0,
  689.                                         TAG_END);
  690.                                     GT_SetGadgetAttrs(CTEGad,EditABWindow,0,
  691.                                         GTCY_Active,DEFAULT_CTE,
  692.                                         TAG_END);
  693.                                     ActualRRT = -1;
  694.                                     ActualCTE = DEFAULT_CTE;
  695.                                     ActiveGadget = UsernameGad;
  696.                                 }
  697.                             }
  698.                             else
  699.                                 SimpleRequest(EditABWindow,"No address selected!");
  700.  
  701.                             break;
  702.                             
  703.                         case UPDATE:
  704.                             if (Address)
  705.                             {
  706.                                 if (TwoGadRequest(EditABWindow,"Update current entry?"))
  707.                                 {
  708.                                     strcpy(Address->Username,(char *)((struct StringInfo *)
  709.                                         UsernameGad->SpecialInfo)->Buffer);
  710.                                     strcpy(Address->Realname,(char *)((struct StringInfo *)
  711.                                         RealnameGad->SpecialInfo)->Buffer);
  712.                                     strcpy(Address->ReplyTo,(char *)((struct StringInfo *)
  713.                                         ReplyToGad->SpecialInfo)->Buffer);
  714.                                     Address->ReturnReceiptTo = ActualRRT;
  715.                                     Address->CTE = ActualCTE;
  716.                                 }
  717.                             }
  718.                             else
  719.                                 SimpleRequest(EditABWindow,"No address selected!");
  720.  
  721.                             break;
  722.  
  723.                         case CLEAR:
  724.                             GT_SetGadgetAttrs(UsernameGad,EditABWindow,0,
  725.                                 GTST_String,"",
  726.                                 TAG_END);
  727.                             GT_SetGadgetAttrs(RealnameGad,EditABWindow,0,
  728.                                 GTST_String,"",
  729.                                 TAG_END);
  730.                             GT_SetGadgetAttrs(ReplyToGad,EditABWindow,0,
  731.                                 GTST_String,"",
  732.                                 TAG_END);
  733.                             GT_SetGadgetAttrs(RRTGad,EditABWindow,0,
  734.                                 GTCY_Active,0,
  735.                                 TAG_END);
  736.                             GT_SetGadgetAttrs(CTEGad,EditABWindow,0,
  737.                                 GTCY_Active,DEFAULT_CTE,
  738.                                 TAG_END);
  739.                             ActualRRT = -1;
  740.                             ActualCTE = DEFAULT_CTE;
  741.                             ActiveGadget = UsernameGad;
  742.  
  743.                             if (Address)
  744.                                 AddHead(&Addressbook,&(Address->Node));
  745.                             Address=0;
  746.  
  747.                             break;
  748.  
  749.                         case RRT:
  750.                             ActualRRT = (ActualRRT+2)%3-1;
  751.                             break;
  752.                         
  753.                         case CTE_:
  754.                             ActualCTE = (ActualCTE+1)%5;
  755.                             break;
  756.                         
  757.                         case ADD:                            
  758.                             /* Username/Realname given? */
  759.                             if (!*((char *)((struct StringInfo *)
  760.                                 UsernameGad->SpecialInfo)->Buffer))
  761.                             {
  762.                                 SimpleRequest(EditABWindow,"No Username!");
  763.                                 break;
  764.                             }
  765.                             if (!*((char *)((struct StringInfo *)
  766.                                 RealnameGad->SpecialInfo)->Buffer))
  767.                             {
  768.                                 SimpleRequest(EditABWindow,"No Realname!");
  769.                                 break;
  770.                             }
  771.                             if (TwoGadRequest(EditABWindow,"Really add?"))
  772.                             {
  773.                                 if (Address) 
  774.                                     AddHead(&Addressbook,&(Address->Node));
  775.                                 AddAddress(&Addressbook,
  776.                                     (char *)((struct StringInfo *)
  777.                                         RealnameGad->SpecialInfo)->Buffer,
  778.                                     (char *)((struct StringInfo *)
  779.                                         UsernameGad->SpecialInfo)->Buffer,
  780.                                     ActualRRT,
  781.                                     (char *)((struct StringInfo *)
  782.                                         ReplyToGad->SpecialInfo)->Buffer,
  783.                                     ActualCTE);
  784.                                 Address = (struct Address *) RemTail(&Addressbook);
  785.                                         
  786.                             }
  787.                             break;
  788.                                 
  789.                         case AB_SORT:
  790.                             SimpleRequest(EditABWindow,"Not yet implemented");
  791.                             break;
  792.  
  793.                         case FIND:
  794.                             if (!Address)
  795.                                 if (!(Address = (struct Address *)RemHead(&Addressbook)))
  796.                                 {
  797.                                     SimpleRequest(EditABWindow,"no addresses!");
  798.                                     break;
  799.                                 }
  800.  
  801.                             StartAddress = Address;
  802.  
  803.                             /* remember Username and Realname for comparision */
  804.                             strncpy(MyUsername,
  805.                                 (char *)((struct StringInfo *)
  806.                                 UsernameGad->SpecialInfo)->Buffer,MAIL_FIELDLENGTH);
  807.                             strncpy(MyRealname,
  808.                                 (char *)((struct StringInfo *)
  809.                                 RealnameGad->SpecialInfo)->Buffer,MAIL_FIELDLENGTH);
  810.  
  811.                             found = FALSE;
  812.                             do
  813.                             {
  814.                                 /* display to make it interesting for the user :-) */
  815.                                 GT_SetGadgetAttrs(UsernameGad,EditABWindow,0,
  816.                                     GTST_String,Address->Username,
  817.                                     TAG_END);
  818.                                 GT_SetGadgetAttrs(RealnameGad,EditABWindow,0,
  819.                                     GTST_String,Address->Realname,
  820.                                     TAG_END);
  821.                                 GT_SetGadgetAttrs(ReplyToGad,EditABWindow,0,
  822.                                     GTST_String,Address->ReplyTo,
  823.                                     TAG_END);
  824.                                 GT_SetGadgetAttrs(RRTGad,EditABWindow,0,
  825.                                     GTCY_Active,Address->ReturnReceiptTo+1,
  826.                                     TAG_END);
  827.                                 GT_SetGadgetAttrs(CTEGad,EditABWindow,0,
  828.                                     GTCY_Active,Address->CTE,
  829.                                     TAG_END);
  830.                                 ActualRRT = Address->ReturnReceiptTo;
  831.                                 ActualCTE = Address->CTE;
  832.  
  833.                                 /* compare */
  834.                                 if (strstr(Address->Username,MyUsername)&&
  835.                                     strstr(Address->Realname,MyRealname))
  836.                                 {
  837.                                     /* found? then break */
  838.                                     found = TRUE;
  839.                                     break;
  840.                                 }
  841.                                 else
  842.                                 {
  843.                                     GT_SetGadgetAttrs(UsernameGad,EditABWindow,0,
  844.                                         GTST_String,MyUsername,
  845.                                         TAG_END);
  846.                                     GT_SetGadgetAttrs(RealnameGad,EditABWindow,0,
  847.                                         GTST_String,MyRealname,
  848.                                         TAG_END);
  849.                                     GT_SetGadgetAttrs(ReplyToGad,EditABWindow,0,
  850.                                         GTST_String,"",
  851.                                         TAG_END);
  852.                                     GT_SetGadgetAttrs(RRTGad,EditABWindow,0,
  853.                                         GTCY_Active,Address->ReturnReceiptTo+1,
  854.                                         TAG_END);
  855.                                     GT_SetGadgetAttrs(CTEGad,EditABWindow,0,
  856.                                         GTCY_Active,Address->CTE,
  857.                                         TAG_END);
  858.                                     ActualRRT = Address->ReturnReceiptTo+1;
  859.                                     ActualCTE = Address->CTE;
  860.                                 }
  861.  
  862.                                 /* goto next */
  863.                                 AddTail(&Addressbook,&(Address->Node));
  864.                                 Address = (struct Address *) RemHead(&Addressbook);
  865.  
  866.                                 
  867.                             }
  868.                             while (Address!=StartAddress);
  869.  
  870.                             if (!found) SimpleRequest(EditABWindow,"Not found");
  871.                             break;
  872.  
  873.                         default:
  874.                             puts("unknown gadget");
  875.                             break;
  876.                     }
  877.                 case MOUSEBUTTONS:
  878.                     break;
  879.                 case INTUITICKS:
  880.                     break;
  881.                 default:
  882.                     printf("Unknkown IntuiMessage->Class:%x\n",Class);
  883.                     break;
  884.             }
  885.  
  886.             ActivateGadget(ActiveGadget,EditABWindow,0);
  887.         }
  888.     }
  889.  
  890.     
  891.     /* remove,free gadgets */
  892.     RemoveGList(EditABWindow,GList,-1); 
  893.     FreeGadgets(GList);
  894.  
  895.     FreeVisualInfo(NextGadget.ng_VisualInfo);
  896.  
  897.     CloseWindow(EditABWindow);
  898.  
  899.     /* write addressbook */
  900.     if (Address)
  901.         AddHead(&Addressbook,&(Address->Node));
  902.     WriteAddressBook(&Addressbook);
  903.  
  904.     return;
  905. }
  906.